package com.have.blog.admin.controller;


import com.have.blog.admin.annotation.operationLogger.OperationLogger;
import com.have.blog.admin.service.AdminLoginService;
import com.have.blog.admin.service.WebConfigService;
import com.have.blog.base.wrapper.Wrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/auth")
@Api(value = "admin登录相关接口", tags = {"admin登录相关接口"})
@Slf4j
public class AdminLoginController {

    @Autowired
    private AdminLoginService adminLoginService;
    @Autowired
    private WebConfigService webConfigService;

    @OperationLogger(value = "admin用户登录")
    @ApiOperation(value = "admin用户登录", notes = "admin用户登录")
    @PostMapping("/login")
    public Wrapper login(HttpServletRequest request,
                         @ApiParam(name = "username", value = "用户名或邮箱或手机号") @RequestParam(name = "username", required = false) String username,
                         @ApiParam(name = "password", value = "密码") @RequestParam(name = "password", required = false) String password,
                         @ApiParam(name = "isRememberMe", value = "是否记住账号密码") @RequestParam(name = "isRememberMe", required = false, defaultValue = "flase") Boolean isRememberMe) {
        return adminLoginService.login(request, username, password, isRememberMe);
    }

    @ApiOperation(value = "admin用户信息", notes = "admin用户信息", response = String.class)
    @GetMapping(value = "/info")
    public Wrapper info() {
        return adminLoginService.info();
    }

    @ApiOperation(value = "获取网站名称", notes = "获取网站名称", response = String.class)
    @GetMapping(value = "/getWebSiteName")
    public Wrapper getWebsiteName() {
        return webConfigService.getWebSiteName();
    }

    @OperationLogger(value = "admin用户退出登录")
    @ApiOperation(value = "退出登录", notes = "退出登录", response = String.class)
    @PostMapping(value = "/logout")
    public Wrapper logout() {
        return adminLoginService.logout();
    }

    @ApiOperation(value = "获取当前用户菜单", notes = "获取当前用户菜单", response = String.class)
    @GetMapping(value = "/getMenu")
    public Wrapper getMenu() {
        return adminLoginService.getMenu();
    }
}
